﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Content;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.CMS.Linq
{
    [Table(Name="dbo.PageTemplateConstraint")]
    public class LinqPageTemplateConstraint : PageTemplateConstraint, IPersistable
    {
        private EntityRef<LinqPageTemplate> proxyRelatedTemplate;

        public LinqPageTemplateConstraint()
        {
            this.proxyRelatedTemplate = default(EntityRef<LinqPageTemplate>);
        }

        [Column(IsPrimaryKey = true)]
        public new Guid Id
        {
            get { return base.Id; }
            set { base.Id = value;  }
        }

        [Column(UpdateCheck = UpdateCheck.Never)]
        public Guid ParentTemplateId
        {
            get; set;
        }

        [Column(UpdateCheck = UpdateCheck.Never)]
        public Guid RelatedTemplateId
        {
            get; set;
        }

        [Column(UpdateCheck = UpdateCheck.Never, CanBeNull =true)]
        public new int? MinimumRequired
        {
            get { return base.MinimumRequired; }
            set { base.MinimumRequired = value; }
        }

        [Column(UpdateCheck = UpdateCheck.Never, CanBeNull=true)]
        public new int? MaximumAllowed
        {
            get { return base.MaximumAllowed; }
            set { base.MaximumAllowed = value; }
        } 

        [Column(UpdateCheck=UpdateCheck.Never)]
        public new string NameConstraint
        {
            get { return base.NameConstraint;  }
            set { base.NameConstraint = value; }
        }

        public override PageTemplate RelatedTemplate
        {
            get
            {
                return ProxyRelatedTemplate;
            }
            set
            {
                ProxyRelatedTemplate = (LinqPageTemplate)value;
            }
        }

        [Association(IsForeignKey=true, ThisKey = "RelatedTemplateId", OtherKey="Id", Storage="proxyRelatedTemplate")]
        public LinqPageTemplate ProxyRelatedTemplate
        {
            get { return this.proxyRelatedTemplate.Entity; }   
            set { this.proxyRelatedTemplate.Entity = value; }
        }
    }
} 
